package edu.calvin.djs32.cs214.interpreters.frontend;

import org.junit.Before;
import org.junit.Test;
import org.norecess.antlr.ANTLRTester;
import static org.norecess.antlr.Assert.assertTree;


public class Hobbes2008ParserTest {
	private ANTLRTester myTester;

	@Before
	public void setUp() {
		myTester = new ANTLRTester(new Hobbes2008FrontEnd());
	}
	
	@Test
	public void shouldRecognizeAnIntegerAsAPRogram() {
		assertTree(Hobbes2008Parser.INTEGER, "(123)", myTester.scanInput("123").parseAs("program"));
	    assertTree(Hobbes2008Parser.INTEGER, "(1563)", myTester.scanInput("1563").parseAs("program"));
	    assertTree(Hobbes2008Parser.INTEGER, "(-0x123f)", myTester.scanInput("-0x123f").parseAs("program"));
	}
	
	@Test(expected = Exception.class)
	public void shouldFailWithTwoIntegersAsAPRogram() {
		myTester.scanInput("123 456").parseAs("program");
	}
	@Test
	public void shouldRecognizeStrings(){
		assertTree(Hobbes2008Parser.STRING, "('foo')", myTester.scanInput("'foo'").parseAs("program"));
		assertTree(Hobbes2008Parser.STRING, "('foo bar')", myTester.scanInput("'foo bar'").parseAs("program"));
		assertTree(Hobbes2008Parser.STRING, "(' ')", myTester.scanInput("' '").parseAs("program"));
	}
	
	@Test(expected = Exception.class)
	public void shouldFailWithTwoStringsAsAProgram(){
		myTester.scanInput("'hello' 'goodbye'").parseAs("program");
	}


}
